#!/bin/bash

help() {
  echo "Register plugin commands"
  echo 
  echo "Usage:"
  echo "  zmicro plugin register <plugin_name>"
  echo ""
}

core() {
  if [[ $# -eq 0 ]]; then
    help
    exit 0
  fi

  while [[ $# -gt 0 ]]; do
    local key=$1
    local value=$2
    case $key in
    -h | --help)
      help
      shift # past key
      exit 0
      ;;
    *)
      break
      ;;
    esac
  done

  local plugin_name=$1

  if [ "$plugin_name" = "" ]; then
    log::error "[$(timestamp)][plugin][register] plugin name is required"
    exit 1
  fi

  if [ "$(plugin::has $plugin_name)" = "false" ]; then
    log::error "[$(timestamp)][plugin][register] plugin $plugin_name not found"
    exit 1
  fi

  plugin::register $plugin_name
}

run() {
  core $@
}

run $@
